package com.example.administrator.caigou51.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ab.util.AbViewUtil;
import com.alibaba.fastjson.JSON;
import com.example.administrator.caigou51.EventBusClass.UpdateShopCarFragment;
import com.example.administrator.caigou51.EventBusClass.UpdateShopCarRedCount;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.bean.GoodsDetailBean;
import com.example.administrator.caigou51.bean.ShopCarBean;
import com.example.administrator.caigou51.global.App;
import com.example.administrator.caigou51.global.Constant;
import com.example.administrator.caigou51.request.BaseResponse;
import com.example.administrator.caigou51.request.ICallBackForRequestServer;
import com.example.administrator.caigou51.request.RequestServerManager;
import com.example.administrator.caigou51.util.ToastUtil;

import java.util.List;

import de.greenrobot.event.EventBus;

/**
 * Created by Administrator on 2016/8/23/023.
 */
public class CheckBugGoodsActivity extends GBaseActivity {
    private TextView textViewGoodsNmae;
    private EditText editTextCount;
    private TextView textViewPiZhunWenZi;
    private TextView textViewShengChangQiYe;
    private TextView textViewChangPinGuiGe;
    private EditText editTextDingGouShuoMing;
    private EditText editTextLianXiRen;
    private EditText editTextLianXiShouJi;
    private EditText editTextEmail;
    private LinearLayout linearLayoutBottom;
    private TextView textViewCancel;
    private TextView textViewSumit;
    private GoodsDetailBean goodsDetailBean;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        super.setContentViewFor720_1280(R.layout.activity_check_buygoods);
        findViewByIds();
        initDatas();
        fillArrayInListView();
    }

    private void findViewByIds() {
        textViewGoodsNmae = (TextView) findViewById(R.id.textViewGoodsNmae);
        editTextCount = (EditText) findViewById(R.id.editTextCount);
        textViewPiZhunWenZi = (TextView) findViewById(R.id.textViewPiZhunWenZi);
        textViewShengChangQiYe = (TextView) findViewById(R.id.textViewShengChangQiYe);
        textViewChangPinGuiGe = (TextView) findViewById(R.id.textViewChangPinGuiGe);
        editTextDingGouShuoMing = (EditText) findViewById(R.id.editTextDingGouShuoMing);
        editTextLianXiRen = (EditText) findViewById(R.id.editTextLianXiRen);
        editTextLianXiShouJi = (EditText) findViewById(R.id.editTextLianXiShouJi);
        editTextEmail = (EditText) findViewById(R.id.editTextEmail);
        textViewCancel = (TextView) findViewById(R.id.textViewCancel);textViewCancel.setOnClickListener(this);
        textViewSumit = (TextView) findViewById(R.id.textViewSumit);textViewSumit.setOnClickListener(this);
    }
    private void initDatas() {
        setTopTitle("补货申请登记");
        goodsDetailBean= (GoodsDetailBean) getIntent().getSerializableExtra(GoodsDetailsActivity.TagGoodsDetailBean);
        textViewGoodsNmae.setText(goodsDetailBean.getTitle());
        textViewChangPinGuiGe.setText(goodsDetailBean.getProduct_spec());

        textViewShengChangQiYe.setText(goodsDetailBean.getCorporation());
        textViewPiZhunWenZi.setText(goodsDetailBean.getReference_number());
        setRightImg(View.VISIBLE,R.drawable.icon_more_net_white);
    }

    @Override
    public void doClickRightImg() {
        App.showPopupWindow(getRightImageView(),CheckBugGoodsActivity.this,-124,-30);
    }

    private void fillArrayInListView() {
    }

    public void TaskQueHuoDengJi(final boolean isloadmore,String itemid,String number,String contact,String email,String mobile,String information) {
        RequestServerManager.getInstanceDIY().handleMethodDIY((GBaseActivity) getActivity(), null, isloadmore, null,
                Constant.getRootUrl() + Constant.Action.Action_QueHuoDengJi, Constant.Action.Action_QueHuoDengJi, RequestServerManager.getInstanceDIY().
                        getRequestParams(Constant.Action.Action_QueHuoDengJi, App.getUserBean().getUserid(),App.getUserBean().getSession_id(),itemid,number,contact,email,mobile,information), BaseResponse.class, new ICallBackForRequestServer<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse result) {
                        // JSONObject jsonObject = (JSONObject) result.getData();
                        ToastUtil.showToast("补货申请成功");
                        Intent intent =new Intent(CheckBugGoodsActivity.this,AddAgainGoodsActivity.class);
                        startActivity(intent);
                    }

                    @Override
                    public void onFail(int type, String errorMsg, String json) {

                    }
                });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId())
        {
            case R.id.textViewSumit:
                String number=editTextCount.getText().toString();
                String contact=editTextLianXiRen.getText().toString();
                String email=editTextEmail.getText().toString();
                String mobile=editTextLianXiShouJi.getText().toString();
                String information=editTextDingGouShuoMing.getText().toString();
                //put(Action.Action_QueHuoDengJi, new String[]{"userid","session_id","itemid","number","contact","email","mobile","information"});
                if (!TextUtils.isEmpty(contact) && !TextUtils.isEmpty(mobile)) {
                    TaskQueHuoDengJi(false,goodsDetailBean.getItemid(),number,contact,email, mobile,information);
                }else
                {
                    ToastUtil.showToast("请填写必填的信息");
                }
                break;
            case R.id.textViewCancel:
                finish();
                break;

        }
    }
}
